#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "customeitem.h"

#include <QList>
#include <QDebug>
#include <QGraphicsWidget>
#include <QGraphicsGridLayout>

const int itemWidth = 100;
const int itemHeight = 100;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    view = new QGraphicsView(this);
    ui->horizontalLayout->addWidget(view);

    scene = new QGraphicsScene();
    view->setScene(scene);
    qDebug() << view->geometry();
    // scene->setSceneRect(-3 * itemWidth , - 3 * itemHeight , 6 * itemWidth , 6 * itemHeight);
    qDebug() << view->geometry();
    qDebug() << scene->sceneRect();


    pixmapItem = new QGraphicsPixmapItem();
    qDebug() << pixmapItem;
    //    pixmapItem->setPos(-300 , -300);

    pixmapItem->setPixmap(QPixmap("F:/pic/1.jpg"));
    //    pixmapItem->setScale(0.01);

    scene->addItem(pixmapItem);
    qDebug()<< pixmapItem->isVisible();
    qDebug()<< view->viewport()->contentsRect().contains(pixmapItem->boundingRect().toRect());
    qDebug()<< view->viewport()->geometry();
    view->viewport()->setStyleSheet("background : black");
    qDebug()<< view->viewport()->size();
    view->viewport()->setFixedSize(800 , 480);
    connect(ui->action , SIGNAL(triggered()) , this , SLOT(setUpItems()));
    connect(ui->action_2 , SIGNAL(triggered()) , this , SLOT(testMem()));

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::setUpItems()
{

    for(int i = 0 ; i < 10000 ; ++ i)
    {
        int *ip = new int(0);
        list.append(ip);
    }



}


void MainWindow::testMem()
{
    for(int i = 0 ; i < 10000 ; ++ i)
    {
        int * ip = list.at(i);
        if(ip != NULL)
            delete ip;

    }
    list.clear();
}
